import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

abstract class Job implements Runnable{
	String name;
	long lastExecutionTime;
	boolean end;
	ScheduledFuture<Job> future;
	
	public Job(){
		this("Anonimous");
	}
	public Job(String name){
		this.name=name;
	}
	
	public void setFuture(ScheduledFuture<Job> future){
		this.future=future;
	}
	
	protected void cancel(){
		future.cancel(false);
	}
}

class MoveJob extends Job{
	float from, to;
	int steps;
	int curStep = 0;
	public MoveJob(float from, float to, int steps){
		super("MoveJob");
		this.from=from;
		this.to=to;
		this.steps = steps;
	}
	@Override
	public void run() {
		
	}
	
	
}
class SumJob extends Job{
	int i = 0;
	
	public SumJob(){
		super("SumJob");
	}
	
	@Override
	public void run() {
		i++;
		Logger.getLogger("Job").info("Sumjob i:"+i +" time "+(System.currentTimeMillis()-lastExecutionTime)) ;
		lastExecutionTime=System.currentTimeMillis();
		
		if(i>1000){
			cancel();
		}
	}
	
}
class SubJob extends Job{
	int i = 1000;
	
	public SubJob(){
		super("SubJob");
	}
	
	@Override
	public void run() {
		i++;
		Logger.getLogger("Job").info("Subjob i:"+i +" time "+(System.currentTimeMillis()-lastExecutionTime)) ;
		lastExecutionTime=System.currentTimeMillis();
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
public class TaskManager {
	ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
	
	public void addJob(Job job, long time){
		executor.scheduleAtFixedRate(job, 0, time, TimeUnit.MILLISECONDS);
	}
	
	public static void main(String[] args) throws InterruptedException {
		TaskManager tm = new TaskManager();
		
		
		tm.addJob(new Job() {@Override public void run() {
			Logger.getLogger("RenderManager").info("Render begins!");
		}}, 75);
		
		tm.addJob(new Job() {@Override public void run() {
			Logger.getLogger("MeshOperator").info("Processing 55 meshes!");
		}}, 75);
		
	}
}